package com.loongtech.bi.manager.game;

import com.loongtech.bi.entity.game.EntityNewRoleSchoolSecondLoss1LevelDistribute;
import com.loongtech.bi.manager.system.GameParamConfigManager;
import com.loongtech.core.jpa.manager.ManagerQueryCacheBase;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class NewRoleSchoolSecondLostLevelDistributeManager extends ManagerQueryCacheBase<EntityNewRoleSchoolSecondLoss1LevelDistribute> {
	private static final long serialVersionUID = 1L;
	
	public List<Object[]> getAllKindRoleNumberGroupByLevel(Date dateStart,String queryPlatform, String queryChannel, String queryServer, String queryJob) {
	    if (GameParamConfigManager.ALL_FLAT.equals(queryJob)) {
            return findByQuery("select level,sum(user_number) from EntityNewRoleSchoolSecondLoss1LevelDistribute where day=:dayStart and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level order by sum(user_number) desc ", "dayStart", dateStart);
        } else {
            return findByQuery("select level,sum(user_number) from EntityNewRoleSchoolSecondLoss1LevelDistribute where day=:dayStart and occupation = " + queryJob + " and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level order by sum(user_number) desc ", "dayStart", dateStart);
        }
	}
	
	/**
	 * 获取所有平台的人数
	 * @return
	 */
	public List<Object[]> getAllKindRoleNumber(Date dateStart,String queryPlatform, String queryChannel, String queryServer, String queryJob)  {
        if (GameParamConfigManager.ALL_FLAT.equals(queryJob)) {
            return findByQuery("select sum(user_number),count(user_number) from EntityNewRoleSchoolSecondLoss1LevelDistribute where day=:dayStart and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' ", "dayStart", dateStart);
        } else {
            return findByQuery("select sum(user_number),count(user_number) from EntityNewRoleSchoolSecondLoss1LevelDistribute where day=:dayStart and occupation= " + queryJob + " and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' ", "dayStart", dateStart);
        }
    }

    /**
     *
     * @param startDate
     * @param endDate
     * @param queryPlatform
     * @param queryChannel
     * @param queryServer
     * @param minLevel
     * @return
     */
    public List<Object[]> getAllKindUserNumberGroupByLevel(Date startDate, Date endDate, String queryPlatform, String queryChannel, String queryServer, int minLevel) {
        return findByQuery("select date_format(day,'%Y-%m-%d'),level,user_number from EntityNewUser1LevelDistribute where day>=:startDate and day<=:endDate and platformid=:queryPlatform and channelid=:queryChannel and serverid=:queryServer and level >= :minLevel ",
                "startDate", startDate,
                "endDate", endDate,
                "queryPlatform", queryPlatform,
                "queryChannel", queryChannel,
                "queryServer", queryServer,
                "minLevel", minLevel);
    }

    public List<Object[]> getKindRoleNumber(Date date,String queryPlatform, String queryChannel, String queryServer) {
        return findByQuery("select level,occupation,sum(user_number) from EntityNewRoleSchoolSecondLoss1LevelDistribute where day=:date and platformid = '"+queryPlatform+"' and channelid = '"+queryChannel+"' and serverid = '"+queryServer+"' group by level,occupation order by level,occupation ", "date", date);
    }
}
